﻿#ifndef MEMSAUTOTESTSOFTWARE_H
#define MEMSAUTOTESTSOFTWARE_H

#include <qmainwindow.h>
#include "ui_MemsAutoTestSoftware.h"
#include "ObjAutoInject.h"
#include "qevent.h"
#include "qfiledialog.h"
#include "TurnTableCodec.h"

#include "LogSaver.h"

class DeviceInfoManager;
class ScriptSaveLoader;
class TcpCodec_Transmit;

class Dialog_SetThermostat;
class Dialog_SetLoadMode;
class Dialog_SetRunningMode;
class SetScriptDialog;
class MainWindow;
class MemsAutoTestSoftware : public QMainWindow,public ObjAutoInject
{
  Q_OBJECT
private://property
  uint deviceId=0;
  int accuracy = 4;
private://dependency
  DeviceInfoManager* deviceInfoManager=Q_NULLPTR;
  TurnTableCodec* turnTableCodec = Q_NULLPTR;
  ScriptSaveLoader* scriptSaveLoader = Q_NULLPTR;
  TcpCodec_Transmit* tcpCodec_Transmit = Q_NULLPTR;
  LogSaver* logSaver = LogSaver::getLogSaver();

  //ui对象
  Ui::MemsAutoTestSoftware ui;
  Dialog_SetThermostat* dialog_setThermostat=Q_NULLPTR;
  Dialog_SetLoadMode* dialog_SetLoadMode=Q_NULLPTR;
  Dialog_SetRunningMode* dialog_SetRunningMode=Q_NULLPTR;
  SetScriptDialog* setScriptDialog = Q_NULLPTR;
  MainWindow* mainWindow=Q_NULLPTR;

public:
  explicit MemsAutoTestSoftware(QWidget* parent = Q_NULLPTR);
  virtual ~MemsAutoTestSoftware();

public:
  void showDevice(uint deviceId);
public slots:
  void slot_updateTurnTableState();
  //对应每个按钮按下信号的槽，部分按钮逻辑较为简单，直接采用了lambda表达式
private	slots:
  //文件
  void slot_file_loadScript();//加载脚本
  void slot_file_saveScript();//保存脚本
  void slot_file_about();//关于本软件
  //控制
  void slot_control_turnTable_run();//运行转台
  void slot_control_thermostat_run();//运行温箱
  //设置
  void slot_set_turnTable_loadMode();//设置转台负载模式
  void slot_set_turnTable_runningMode();//设置转台运动模式
  void slot_set_thermostat_targetTemperature();//设置温箱温度
  void slot_set_script();//设置脚本
  //对应各种反馈
private  slots:
  //接收转台反馈
  void slot_turnTableErrorEcho(TurnTableCodec::ErrorFlag errorFlag);

  //转发器反馈
  void slot_showResult(uchar result);
  //脚本管理器反馈
  void slot_scriptIsStarted();
  void slot_scriptIsStoped();

  //接收脚本保存加载器的反馈
  void slot_loadScriptFileFailed(QString filePath);
  void slot_saveScriptFileFailed(QString filePath);

  void initSignalsAndSlots();

private:
  void showMessage(QString msg);

  //代码优化,模块化
private:
  void initAllUI();

  //事件处理
protected:
  virtual void closeEvent(QCloseEvent* event)override;
  virtual void showEvent(QShowEvent *event)override;
  //geter and seter
public:
  uint getDeviceId()const;
  MemsAutoTestSoftware* setDeviceId(uint deviceId);
  DeviceInfoManager* getDeviceInfoManager()const;
  MemsAutoTestSoftware* setDeviceInfoManager(DeviceInfoManager* const deviceInfoManager);
  TurnTableCodec* getTurnTableCodec();
  void setTurnTableCodec(TurnTableCodec* turnTableCodec);
  ScriptSaveLoader* getScriptSaveLoader();
  void setScriptSaveLoader(ScriptSaveLoader* scriptSaveLoader);
  TcpCodec_Transmit* getTcpCodec_Transmit()const;
  MemsAutoTestSoftware* setTcpCodec_Transmit(TcpCodec_Transmit* const tcpCodec_Transmit);
  //ui
  Dialog_SetThermostat* getDialog_setThermostat()const;
  MemsAutoTestSoftware* setDialog_setThermostat(Dialog_SetThermostat* const dialog_setThermostat);
  Dialog_SetLoadMode* getDialog_SetLoadMode()const;
  MemsAutoTestSoftware* setDialog_SetLoadMode(Dialog_SetLoadMode* const dialog_SetLoadMode);
  Dialog_SetRunningMode* getDialog_SetRunningMode()const;
  MemsAutoTestSoftware* setDialog_SetRunningMode(Dialog_SetRunningMode* const dialog_SetRunningMode);
  SetScriptDialog* getSetScriptDialog();
  void setSetScriptDialog(SetScriptDialog* setScriptDialog);
  MainWindow* getMainWindow()const;
  MemsAutoTestSoftware* setMainWindow(MainWindow*const mainWindow);
  int getAccuracy();
  void setAccuracy(int accuracy);
public:
  virtual void objectAutoInjection(QHash<QString,QObject*>* objMap)override;
};
#endif
